package file_util

import "strings"

const _SEPERATOR_UNIX = "/"
const _SEPERATOR_WINDOWS = "\\"

// 拼接路径
func JoinPath(dir string, path string) string {
	dir = strings.TrimSuffix(dir, " ")
	path = strings.TrimPrefix(path, " ")

	if strings.HasSuffix(dir, _SEPERATOR_UNIX) || strings.HasSuffix(dir, _SEPERATOR_WINDOWS) {
		path = strings.TrimPrefix(path, _SEPERATOR_UNIX)
		path = strings.TrimPrefix(path, _SEPERATOR_WINDOWS)
	} else {
		if !strings.HasPrefix(path, _SEPERATOR_UNIX) && !strings.HasPrefix(path, _SEPERATOR_WINDOWS) {
			if strings.Contains(dir, _SEPERATOR_WINDOWS) || strings.Contains(path, _SEPERATOR_WINDOWS) {
				dir = dir + _SEPERATOR_WINDOWS
			} else {
				dir = dir + _SEPERATOR_UNIX
			}
		}
	}

	return (dir + path)
}
